package com.medsoft.drpcp;

import java.util.HashMap;
import java.util.Map;

public class ServiceDefinitionContainer {
	private static final Map<String,ServiceDefinition> services = new HashMap<String,ServiceDefinition>();
	private static final Map<String,String> methodServiceMap = new HashMap<String,String>();
	
	public static ServiceDefinition getService(String serviceId) {
		return services.get(serviceId);
	}
	
	public static void addService(String serviceId,ServiceDefinition service) {
		if (services.containsKey(serviceId)) {
			throw new RuntimeException("drpcp service id [" + serviceId + "] is duplicate!");
		}
		services.put(serviceId, service);
		methodServiceMap.put(service.getMethod().getName(), serviceId);
	}
	
	public static ServiceDefinition getServiceByMethodName(String method) {
		return services.get(methodServiceMap.get(method));
	}
	
	public static Map<String,ServiceDefinition> getAllService() {
		return services;
	}
}
